import { defineConfig, loadEnv } from 'vite'
import react from '@vitejs/plugin-react'
import { resolve } from "path"
import qiankun from 'vite-plugin-qiankun'
import { renderWithQiankun, qiankunWindow } from 'vite-plugin-qiankun/dist/helper';

// console.log('qiankunWindow', qiankunWindow)
// const pluginCig = qiankunWindow.__POWERED_BY_QIANKUN__ ? [] : [react()]
export default defineConfig(({mode}) => {
  const env = loadEnv(mode, process.cwd())
  return {
    base: '/react-app/',
    plugins: [
      // react(),
      // ...pluginCig,
      qiankun('subReactAPP', { useDevMode: true })
    ],
    server: {
      open: true,
      port: 3002,
      host: '0.0.0.0',
    },
    resolve: {
      alias: {
        '@': resolve(__dirname, 'src')
      }
    },
    build: {
      rollupOptions: {
        external: /^src\/mock/  // 打包配置优化
      },
      outDir: 'dist/sub-react-app'
    },
    // base: env.VITE_PACK_PATH // 配置打包路径
  }
})
